<template>
    <TabGrayEasyCard :title="'保证金押金'" :isMore="false" @onMore="goDetail(props.permi)" :tabs="card.tabs" :curTab="card.curTab"
        :tabRight="card.tabRight" @onChange="changeTab" :grayCardList="card.grayCardList" :lineText="''" :barText="''"
        :unitText="``" :updateText="card.updateText"
        v-btnPermi="{ permi: props.permi, noReport: true, isHiden: true, hideList: props.hideList }">
        <slot>
            <el-table :data="card.tableData" height="100%">
                <el-table-column prop="bulidLab" :label="tableLabel" :align="'left'" />
                <el-table-column label="应收" :align="'right'">
                    <template #default="scope">
                        {{ toThousands(scope.row.invrecamtl) }}
                    </template>
                </el-table-column>
                <el-table-column label="实收" :align="'right'">
                    <template #default="scope">
                        {{ toThousands(scope.row.invincomeamtl) }}
                    </template>
                </el-table-column>
                <el-table-column label="未交" :align="'right'">
                    <template #default="scope">
                        {{ toThousands(scope.row.debtamt) }}
                    </template>
                </el-table-column>
            </el-table>
        </slot>
    </TabGrayEasyCard>
</template>

<script setup>
import TabGrayEasyCard from '@/DbComponents/tabGrayEasyCard'
import { toThousands } from '@/utils/number-util'
import dashBoardApi from '@/api/Manage/Business/dashBoard'
import { ref, reactive, watch, computed } from 'vue'
import { reportLog } from '@/utils/reportLog'

const props = defineProps({
    permi: {
        type: String,
        required: false,
        default: ''
    },
    hideList: {
        type: Array,
        required: false,
    },
    biProjectCode: {
        type: String,
        required: false,
        default: ''
    },
    updateDate: {
        type: String,
        required: false,
        default: ''
    }
})
const card = reactive(
    {
        tabs: [{ label: '保证金', value: '保证金' }, { label: '押金', value: '押金' }],
        curTab: '保证金',
        tabRight: '',
        grayCardList: [{ label: '应收', value: '', unit: '万', color: '' }, { label: '实收', value: '', unit: '万', color: '' }, { label: '未交', value: '', unit: '万', color: '' }],
        unitText: '',
        updateText: '',
        tableData: [],
        // startDate: '',
        // endDate: '',
    }
)
const getCardData = () => {
    dashBoardApi.manageGuaranteeCardApi({ biProjectCode: props.biProjectCode, chargeclass: card.curTab }).then((res) => {
        if (res.data.code == 200) {
            card.tabRight = res.data.data.datetime
            card.grayCardList[0].value = toThousands(res.data.data.invrecamtl)
            card.grayCardList[1].value = toThousands(res.data.data.invincomeamtl)
            card.grayCardList[2].value = toThousands(res.data.data.debtamt)
            card.unitText = res.data.data.unit
        }
    }).catch(err => {
        console.log(err)
    });
}
const getChartData = () => {
    dashBoardApi.manageGuaranteeCardListApi({ biProjectCode: props.biProjectCode, chargeclass: card.curTab }).then((res) => {
        if (res.data.code == 200) {
            card.tableData = res.data.data
        }
    }).catch(err => {
        console.log(err)
    });
}

const goDetail = (permi) => {
    reportLog({
        type: 4,
        resourceKey: permi,
    })
}
const changeTab = (value) => {
    // 切换tab，更换开始和结束日期
    // 按天：开始和结束日期，均为【数据更新日期】
    // 按月：开始日期为【数据更新日期】当月第一天，结束日期为【数据更新日期】
    // 按年：开始日期为【数据更新日期】当年第一天，结束日期为【数据更新日期】
    card.curTab = value
    getCardData()
    getChartData()
}



let tableLabel = ref('楼层')
const getBuilding = () => {
    dashBoardApi.isBuildingsApi({ biProjectCode: props.biProjectCode }).then((res) => {
        if (res.code == 200) {
            tableLabel.value = res.data ? '楼栋' : '楼层'
        }
    }).catch(err => {
        console.log(err)
    });
}
getBuilding()
getCardData()
getChartData()

const biProjectCode = computed(() => {
    return props.biProjectCode
});
watch(biProjectCode, () => {
    getBuilding()
    getCardData()
    getChartData()
}, { deep: true });

</script>

<style scoped lang="scss"></style>
